package com.zzq.service.v1.impl;

import com.zzq.config.K8sInit;
import com.zzq.service.v1.NamespaceService;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1NamespaceList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class NamespaceServiceImpl implements NamespaceService {

    @Autowired
    private K8sInit k8sInit;

    @Override
    public V1NamespaceList getNamespace() {
            ApiClient client = k8sInit.getConnection();
            CoreV1Api apiInstance = new CoreV1Api();
            String pretty = "true";
            V1NamespaceList namespaceList = new V1NamespaceList();
            try {
                namespaceList = apiInstance.listNamespace(null, pretty, null, null, null, null, null, null, null);
            } catch (ApiException e) {
                System.err.println("Exception when calling CoreV1Api#listNamespace");
                e.printStackTrace();
            }
            return namespaceList;
        }
}
